package com.likelist.model;

import java.sql.*;
import javax.sql.*;
import javax.naming.*;

public class Like_listDAO implements Like_listDAO_interface {

	private static DataSource ds;
	
	private static String INSERT_STMT = "INSERT INTO LIKE_LIST (MACCOUNT ,GOODSNO) VALUES (? ,?)";
	private static String DELETE_STMT = "DELETE FROM LIKE_LIST WHERE MACCOUNT = ? AND GOODSNO = ?";

	static {
		try {
			Context ctx = new InitialContext();
			ds = (DataSource) ctx.lookup("java:comp/env/jdbc/ProjectDB");
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
	}
	
	@Override
	public void insert(Like_listVO lVO) {
		Connection con = null;
		PreparedStatement pst = null;


			try {
				con = ds.getConnection();
				pst = con.prepareStatement(INSERT_STMT);
				
				pst.setString(1, lVO.getMaccount());
				pst.setInt(2, lVO.getGoodsno());
				pst.executeUpdate();
				
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} finally {
				if(pst != null)
					try {
						pst.close();
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				if(con != null)
					try {
						con.close();
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}		
	}

	@Override
	public void delete(String mAccount, Integer goodsNo) {
		Connection con = null;
		PreparedStatement pst = null;


			try {
				con = ds.getConnection();
				pst = con.prepareStatement(DELETE_STMT);
				
				pst.setString(1, mAccount);
				pst.setInt(2, goodsNo);
				pst.executeUpdate();
		
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} finally {
				if(pst != null)
					try {
						pst.close();
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				if(con != null)
					try {
						con.close();
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
	}

//	@Override
//	public List<Like_listVO> findByMAccount(String mAccount) {
//	
//		return null;
//	}

}
